package GUI;

import javax.swing.AbstractButton;
import javax.swing.Box;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.*;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JTextPane;
import javax.swing.JSpinner;

import Messages.MessageGetAllTelephoneOrdersForDate;
import Messages.MessageGetAllTelephoneOrdersForDateReply;
import Messages.MessageGetMenuTableDetails;
import Messages.MessageGetMenuTableReply;
import Messages.MessageShowAllEmployees;
import Messages.MessageShowAllEmployeesReply;
import Messages.MessageShowAllInventory;
import Messages.MessageShowAllInventoryReply;
import Messages.MessageShowAllTablesOfThisShift;
import Messages.MessageShowAllTablesOfThisShiftReply;

import Messages.MessageShowBusinessMenusReply;
import Messages.MessageShowAllStandardsMenus;
import Messages.MessageShowAllStandardsMenusReply;
import Messages.MessageShowAllSuppliers;
import Messages.MessageShowAllSuppliersReply;
import Messages.MessageShowBusinessMenus;


/**
 * this class creates the panel with main buttons of the application 
 * the panel is located in a top part of a screen
 * the panel includes  buttons that switches parts of our program:
 * suppliers, inventory, tables, orders, employees, menus
 * 
 * 
 * @author igor
 *
 */
public class PanelButtons extends JPanel {
	private MainMenu mainMenu;
	private JButton button_exit;
	private JButton button_suppliers;
	private JButton button_orders;
	public JButton button_tables;
	private JButton button_clockIn;
	private JButton button_inventory;
	private JButton button_employee;
	private JButton button_menu;
	private JButton button_management_menu;
	private JButton button_kitchen;
	private JButton button_report_tables;

	public PanelButtons(MainMenu mm) {
		super();
		this.mainMenu = mm;
		this.setPreferredSize(new Dimension(500, 100));
		this.setBackground(new Color(204, 153, 153));
		this.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		//this.add(getLogo());
		this.add(Box.createHorizontalStrut(200));
		//this.add(get_button_exit());
		this.add(get_button_report_tables());
		this.add(get_button_kitchen());
		this.add(get_button_suppliers());
		this.add(get_button_inventory());
		this.add(get_button_orders());
		this.add(get_button_tables());
		this.add(get_button_clockIn());
		this.add(get_button_employee());
		this.add(get_button_menu());
		this.add(get_button_management_menu());
		this.add(getTimePanel());
	}

	/**
	 * panel with digital clock(use class DigitalClock that return label clock)
	 * 
	 * @return timePanel
	 */
	
	/*private JLabel getLogo()
	{
		Icon logoIcon=new ImageIcon("logo-icon.png");
		Image img = ((ImageIcon) logoIcon).getImage();
		Image newimg = img.getScaledInstance(250, 100,java.awt.Image.SCALE_SMOOTH);
		logoIcon = new ImageIcon(newimg);
		JLabel logoLabel=new JLabel(logoIcon);
		return logoLabel;
		
	}*/
	
	private JPanel getTimePanel() // panel with digital clock(use class
									// DigitalClock that return label clock)
	{

		JPanel timePanel = new JPanel();
		timePanel.setBackground(this.getBackground());
		DigitalClock dc = new DigitalClock();
		JLabel lblTime = new JLabel();
		lblTime = dc.getTimeLabel();
		lblTime.setBorder(null);
		timePanel.add(lblTime);
		// timePanel.add(new JSeparator(SwingConstants.HORIZONTAL));
		return timePanel;
	}

	/**
	 * initialize exit button
	 * this button will close the application
	 */
	private JButton get_button_exit() {
		if (button_exit == null) {
			Icon exitIcon = new ImageIcon("exit-icon.png");
			Image img = ((ImageIcon) exitIcon).getImage();
			Image newimg = img.getScaledInstance(40, 40,
					java.awt.Image.SCALE_SMOOTH);
			exitIcon = new ImageIcon(newimg);
			button_exit = new JButton("יציאה", exitIcon);
			button_exit.setVerticalTextPosition(AbstractButton.BOTTOM);
			button_exit.setHorizontalTextPosition(AbstractButton.CENTER);
			button_exit
					.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			button_exit.setPreferredSize(new Dimension(110, 90));

			button_exit.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					
					
					//for kill thread
					((BorderLayout) mainMenu
							.getContentPane().getLayout())
							.getLayoutComponent(BorderLayout.CENTER).setVisible(false);
					//////////////////////

				}
			});
		}
		return button_exit;
	}

	private JButton get_button_report_tables() {
		if (button_report_tables == null) {
			Icon kitchenIcon = new ImageIcon("manager.png");
			Image img = ((ImageIcon) kitchenIcon).getImage();
			Image newimg = img.getScaledInstance(40, 40,
					java.awt.Image.SCALE_SMOOTH);
			kitchenIcon = new ImageIcon(newimg);
			button_report_tables = new JButton("ניהול ", kitchenIcon);
			button_report_tables.setVerticalTextPosition(AbstractButton.BOTTOM);
			button_report_tables.setHorizontalTextPosition(AbstractButton.CENTER);
			button_report_tables
					.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			button_report_tables.setPreferredSize(new Dimension(110, 90));

			button_report_tables.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					
					
					MessageShowAllTablesOfThisShift msgShowMenu = new MessageShowAllTablesOfThisShift();
					try {
						mainMenu.ms.client.sendToServer(msgShowMenu);
						MessageShowAllTablesOfThisShiftReply result = (MessageShowAllTablesOfThisShiftReply) mainMenu.ms.client
								.GetMessage();
						
						PfShowAllTableOfThisShift tables=new PfShowAllTableOfThisShift(mainMenu,result.getResult());
						if(((BorderLayout) mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST)!=null)
						{
						mainMenu.getContentPane()
								.remove(((BorderLayout) mainMenu
										.getContentPane().getLayout())
										.getLayoutComponent(BorderLayout.EAST));
						}
						mainMenu.getContentPane()
								.remove(((BorderLayout) mainMenu
										.getContentPane().getLayout())
										.getLayoutComponent(BorderLayout.CENTER));
						mainMenu.getContentPane().add(
								new PanelFunctionTablesManager(mainMenu,tables),
								BorderLayout.EAST);
						
						
						mainMenu.getContentPane().add(tables,
						BorderLayout.CENTER);
						
						mainMenu.getContentPane().validate();
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					

				}
			});
		}
		return button_report_tables;
	}
	
	private JButton get_button_kitchen() {
		if (button_kitchen == null) {
			Icon kitchenIcon = new ImageIcon("kitchen-icon.png");
			Image img = ((ImageIcon) kitchenIcon).getImage();
			Image newimg = img.getScaledInstance(40, 40,
					java.awt.Image.SCALE_SMOOTH);
			kitchenIcon = new ImageIcon(newimg);
			button_kitchen = new JButton("מטבח", kitchenIcon);
			button_kitchen.setVerticalTextPosition(AbstractButton.BOTTOM);
			button_kitchen.setHorizontalTextPosition(AbstractButton.CENTER);
			button_kitchen
					.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			button_kitchen.setPreferredSize(new Dimension(110, 90));

			button_kitchen.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					
					
					//for kill thread
					((BorderLayout) mainMenu
							.getContentPane().getLayout())
							.getLayoutComponent(BorderLayout.CENTER).setVisible(false);
					//////////////////////
					
					if(((BorderLayout) mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST)!=null)
					{
					mainMenu.getContentPane().remove(((BorderLayout) mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST));
					}
					mainMenu.getContentPane().remove(((BorderLayout) mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
					mainMenu.getContentPane().add(new PfKitchen(mainMenu),BorderLayout.CENTER);
					//mainMenu.getContentPane().add(new PanelFunctionsEmpty(mainMenu),BorderLayout.EAST);
					mainMenu.getContentPane().validate();
					

				}
			});
		}
		return button_kitchen;
	}
	
	
	
	/**
	 * initialize suppliers button
	 * this button switches to supplier handle operations
	 * 
	 * @return JButton supplier
	 */
	private JButton get_button_suppliers() {
		if (button_suppliers == null) {
			Icon suppliersIcon = new ImageIcon("suppliers-icon.png");
			Image img = ((ImageIcon) suppliersIcon).getImage();
			Image newimg = img.getScaledInstance(45, 45,
					java.awt.Image.SCALE_SMOOTH);
			suppliersIcon = new ImageIcon(newimg);
			button_suppliers = new JButton("ספקים", suppliersIcon);
			if(this.mainMenu.getUser().getPermission()==1)                     //set permission
				button_suppliers.setEnabled(false);
			button_suppliers.setVerticalTextPosition(AbstractButton.BOTTOM);
			button_suppliers.setHorizontalTextPosition(AbstractButton.CENTER);
			button_suppliers.setFont(new Font("Tahoma",
					Font.BOLD | Font.ITALIC, 15));
			button_suppliers.setPreferredSize(new Dimension(110, 90));

			button_suppliers
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {

							((BorderLayout) mainMenu
									.getContentPane().getLayout())
									.getLayoutComponent(BorderLayout.CENTER).setVisible(false);
							
							MessageShowAllSuppliers msgShowSupp = new MessageShowAllSuppliers();
							
							try {
								mainMenu.ms.client.sendToServer(msgShowSupp);
								MessageShowAllSuppliersReply resultSupp = (MessageShowAllSuppliersReply) mainMenu.ms.client
										.GetMessage();
								
								if(((BorderLayout) mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST)!=null)
								{
								mainMenu.getContentPane()
										.remove(((BorderLayout) mainMenu
												.getContentPane().getLayout())
												.getLayoutComponent(BorderLayout.EAST));
								}
								mainMenu.getContentPane()
										.remove(((BorderLayout) mainMenu
												.getContentPane().getLayout())
												.getLayoutComponent(BorderLayout.CENTER));
								mainMenu.getContentPane().add(
										new PfSearch_supplier(mainMenu,
												resultSupp.getResult()),
										BorderLayout.CENTER);
								mainMenu.getContentPane().add(
										new PanelFunctionsSuppliers(mainMenu),
										BorderLayout.EAST);
								mainMenu.getContentPane().validate();
							} catch (IOException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							}

						}
					});
		}
		return button_suppliers;
	}
	
	
	/**
	 * initialize inventory button
	 * this button switches to inventory handle operations
	 * 
	 * @return JButton inventory
	 */

	@SuppressWarnings("deprecation")
	private JButton get_button_inventory() {
		if (button_inventory == null) {
			Icon inventoryIcon = new ImageIcon("inventory-icon.png");
			Image img = ((ImageIcon) inventoryIcon).getImage();
			Image newimg = img.getScaledInstance(45, 45,
					java.awt.Image.SCALE_SMOOTH);
			inventoryIcon = new ImageIcon(newimg);
			button_inventory = new JButton("מלאי", inventoryIcon);
			if(this.mainMenu.getUser().getPermission()==1)                      //set permissions
				button_inventory.setEnabled(false);
			button_inventory.setVerticalTextPosition(AbstractButton.BOTTOM);
			button_inventory.setHorizontalTextPosition(AbstractButton.CENTER);
			button_inventory.setFont(new Font("Tahoma",
					Font.BOLD | Font.ITALIC, 15));
			button_inventory.setPreferredSize(new Dimension(110, 90));

			button_inventory
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
							
							((BorderLayout) mainMenu
									.getContentPane().getLayout())
									.getLayoutComponent(BorderLayout.CENTER).setVisible(false);
							
							
							MessageShowAllInventory msgShowInv = new MessageShowAllInventory();

							try {
								
								mainMenu.ms.client.sendToServer(msgShowInv);
								MessageShowAllInventoryReply resultInv = (MessageShowAllInventoryReply) mainMenu.ms.client
										.GetMessage();
								
								if(((BorderLayout) mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST)!=null)
								{
								mainMenu.getContentPane()
										.remove(((BorderLayout) mainMenu
												.getContentPane().getLayout())
												.getLayoutComponent(BorderLayout.EAST));
								}
								mainMenu.getContentPane()
										.remove(((BorderLayout) mainMenu
												.getContentPane().getLayout())
												.getLayoutComponent(BorderLayout.CENTER));
								mainMenu.getContentPane().add(
										new PanelFunctionsInventory(mainMenu),
										BorderLayout.EAST);
								
								mainMenu.getContentPane().add(new PfShowAllInventory(mainMenu,
										resultInv.getResult()),
								BorderLayout.CENTER);
								
								mainMenu.getContentPane().validate();
							} catch (IOException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							}
							
						}
					});
		}
		return button_inventory;
	}

	/**
	 * initialize telephone orders button
	 * this button switches to telephone orders  handle operations
	 * 
	 * @return JButton orders
	 */
	private JButton get_button_orders() {
		if (button_orders == null) {
			Icon phoneIcon = new ImageIcon("phone-icon.png");
			Image img = ((ImageIcon) phoneIcon).getImage();
			Image newimg = img.getScaledInstance(45, 45,
					java.awt.Image.SCALE_SMOOTH);
			phoneIcon = new ImageIcon(newimg);
			button_orders = new JButton("הזמנות", phoneIcon);
			button_orders.setVerticalTextPosition(AbstractButton.BOTTOM);
			button_orders.setHorizontalTextPosition(AbstractButton.CENTER);
			button_orders.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC,
					15));
			button_orders.setPreferredSize(new Dimension(110, 90));

			button_orders
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
							
							((BorderLayout) mainMenu
									.getContentPane().getLayout())
									.getLayoutComponent(BorderLayout.CENTER).setVisible(false);
							
							DateFormat dateFormat = new SimpleDateFormat(
									"yyyy/MM/dd");
							Date date = new Date();
							// System.out.println(dateFormat.format(date));
							MessageGetAllTelephoneOrdersForDate msgAllOrders = new MessageGetAllTelephoneOrdersForDate(
									dateFormat.format(date));
							try {
								mainMenu.ms.client.sendToServer(msgAllOrders);
								MessageGetAllTelephoneOrdersForDateReply resultOrders = (MessageGetAllTelephoneOrdersForDateReply) mainMenu.ms.client
										.GetMessage();
								if(((BorderLayout) mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST)!=null)
								{
								mainMenu.getContentPane()
										.remove(((BorderLayout) mainMenu
												.getContentPane().getLayout())
												.getLayoutComponent(BorderLayout.EAST));
								}
								mainMenu.getContentPane()
										.remove(((BorderLayout) mainMenu
												.getContentPane().getLayout())
												.getLayoutComponent(BorderLayout.CENTER));
								PFTelephone_orders telOrders = new PFTelephone_orders(
										mainMenu, resultOrders.getResult());
								mainMenu.getContentPane().add(telOrders,
										BorderLayout.CENTER);
								mainMenu.getContentPane().add(
										new PanelFunctionsOrders(mainMenu,
												telOrders), BorderLayout.EAST);
								mainMenu.getContentPane().validate();
							} catch (IOException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							}
						}
					});
		}
		return button_orders;
	}

	
	/**
	 * initialize tables button
	 * this button switches to tables handle operations
	 * 
	 * @return JButton tables
	 */
	private JButton get_button_tables() {
		if (button_tables == null) {
			Icon tableIcon = new ImageIcon("table_icon.png");
			Image img = ((ImageIcon) tableIcon).getImage();
			Image newimg = img.getScaledInstance(45, 45,
					java.awt.Image.SCALE_SMOOTH);
			tableIcon = new ImageIcon(newimg);
			button_tables = new JButton("שולחנות", tableIcon);
			button_tables.setVerticalTextPosition(AbstractButton.BOTTOM);
			button_tables.setHorizontalTextPosition(AbstractButton.CENTER);
			button_tables.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC,
					15));
			button_tables.setPreferredSize(new Dimension(110, 90));

			button_tables
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
							
							//for kill thread
							((BorderLayout) mainMenu
									.getContentPane().getLayout())
									.getLayoutComponent(BorderLayout.CENTER).setVisible(false);
							//////////////////////
							
							if(((BorderLayout) mainMenu
											.getContentPane().getLayout())
											.getLayoutComponent(BorderLayout.EAST)!=null)
								if(((BorderLayout) mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST)!=null)
								{
								mainMenu.getContentPane()
										.remove(((BorderLayout) mainMenu
												.getContentPane().getLayout())
												.getLayoutComponent(BorderLayout.EAST));
								}
							
							mainMenu.getContentPane()
									.remove(((BorderLayout) mainMenu
											.getContentPane().getLayout())
											.getLayoutComponent(BorderLayout.CENTER));
							mainMenu.getContentPane().add(
									new PfScheem_All_Tables(mainMenu),
									BorderLayout.CENTER);
						//	mainMenu.getContentPane().add(
						//			new PanelFunctionsTables(mainMenu),
						//			BorderLayout.EAST);
							// mainMenu.getContentPane().add(new JPanel(),
							// BorderLayout.CENTER);
							mainMenu.getContentPane().validate();

						}
					});
		}
		return button_tables;
	}

	
	
	/**
	 * initialize clock-In clock-Out button
	 * this button switches to clock-In clock-Out handle operations
	 * 
	 * @return JButton clock-In
	 */
	private JButton get_button_clockIn() {
		if (button_clockIn == null) {
			Icon clockInIcon = new ImageIcon("clockIn-icon.png");
			Image img = ((ImageIcon) clockInIcon).getImage();
			Image newimg = img.getScaledInstance(45, 45,
					java.awt.Image.SCALE_SMOOTH);
			clockInIcon = new ImageIcon(newimg);
			button_clockIn = new JButton("כניסה/יציאה", clockInIcon);
			button_clockIn.setVerticalTextPosition(AbstractButton.BOTTOM);
			button_clockIn.setHorizontalTextPosition(AbstractButton.CENTER);
			button_clockIn.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC,
					15));
			button_clockIn.setPreferredSize(new Dimension(110, 90));

			button_clockIn
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
							((BorderLayout) mainMenu
									.getContentPane().getLayout())
									.getLayoutComponent(BorderLayout.CENTER).setVisible(false);
							if(((BorderLayout) mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST)!=null)
							{
							mainMenu.getContentPane()
									.remove(((BorderLayout) mainMenu
											.getContentPane().getLayout())
											.getLayoutComponent(BorderLayout.EAST));
							}
							 mainMenu.getContentPane()
									.remove(((BorderLayout) mainMenu
											.getContentPane().getLayout())
											.getLayoutComponent(BorderLayout.CENTER));
							mainMenu.getContentPane().add(
									new PfClock_In_Out_First(mainMenu),
									BorderLayout.CENTER);
							 mainMenu.getContentPane().add(new
									 PanelFunctionEmptyWithoutKeyboard(mainMenu),
							 BorderLayout.EAST);

							mainMenu.getContentPane().validate();
						}
					});
		}
		return button_clockIn;
	}

	
	/**
	 * initialize employee button
	 * this button switches to employee handle operations
	 * 
	 * @return JButton employee
	 */
	private JButton get_button_employee() {
		if (button_employee == null) {
			Icon employeeIcon = new ImageIcon("employee-icon.png");
			Image img = ((ImageIcon) employeeIcon).getImage();
			Image newimg = img.getScaledInstance(45, 45,
					java.awt.Image.SCALE_SMOOTH);
			employeeIcon = new ImageIcon(newimg);
			button_employee = new JButton("עובדים", employeeIcon);
			button_employee.setVerticalTextPosition(AbstractButton.BOTTOM);
			button_employee.setHorizontalTextPosition(AbstractButton.CENTER);
			button_employee.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC,
					15));
			button_employee.setPreferredSize(new Dimension(110, 90));

			button_employee
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
							
							((BorderLayout) mainMenu
									.getContentPane().getLayout())
									.getLayoutComponent(BorderLayout.CENTER).setVisible(false);

							MessageShowAllEmployees msgShowEmp = new MessageShowAllEmployees();

							try {
								mainMenu.ms.client.sendToServer(msgShowEmp);
								MessageShowAllEmployeesReply result = (MessageShowAllEmployeesReply) mainMenu.ms.client
										.GetMessage();
								if(((BorderLayout) mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST)!=null)
								{
								mainMenu.getContentPane()
										.remove(((BorderLayout) mainMenu
												.getContentPane().getLayout())
												.getLayoutComponent(BorderLayout.EAST));
								}
								mainMenu.getContentPane()
										.remove(((BorderLayout) mainMenu
												.getContentPane().getLayout())
												.getLayoutComponent(BorderLayout.CENTER));
								mainMenu.getContentPane().add(
										new PfSearch_employee(mainMenu, result
												.getResult()),
										BorderLayout.CENTER);
								mainMenu.getContentPane().add(
										new PanelFunctionsEmployees(mainMenu),
										BorderLayout.EAST);
								mainMenu.getContentPane().validate();

							} catch (IOException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							}

						}
					});
		}
		return button_employee;
	}

	
	
	/**
	 * initialize menu button
	 * this button switches to menu handle operations
	 * 
	 * @return JButton menu
	 */
	private JButton get_button_menu() {
		if (button_menu == null) {
			Icon menuIcon = new ImageIcon("menu-icon.png");
			Image img = ((ImageIcon) menuIcon).getImage();
			Image newimg = img.getScaledInstance(45, 45,
					java.awt.Image.SCALE_SMOOTH);
			menuIcon = new ImageIcon(newimg);
			button_menu = new JButton("תפריט", menuIcon);
			button_menu.setVerticalTextPosition(AbstractButton.BOTTOM);
			button_menu.setHorizontalTextPosition(AbstractButton.CENTER);
			button_menu
					.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			button_menu.setPreferredSize(new Dimension(110, 90));

			button_menu.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					
					
					((BorderLayout) mainMenu
							.getContentPane().getLayout())
							.getLayoutComponent(BorderLayout.CENTER).setVisible(false);

					MessageGetMenuTableDetails msgShowMenu = new MessageGetMenuTableDetails();
					try {
						mainMenu.ms.client.sendToServer(msgShowMenu);
						MessageGetMenuTableReply result = (MessageGetMenuTableReply) mainMenu.ms.client
								.GetMessage();
						if(((BorderLayout) mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST)!=null)
						{
						mainMenu.getContentPane()
								.remove(((BorderLayout) mainMenu
										.getContentPane().getLayout())
										.getLayoutComponent(BorderLayout.EAST));
						}
					/*	mainMenu.getContentPane()
								.remove(((BorderLayout) mainMenu
										.getContentPane().getLayout())
										.getLayoutComponent(BorderLayout.CENTER));*/
						mainMenu.getContentPane().add(
								new PanelFunctionsMenu(mainMenu,result.getMenues()),
								BorderLayout.EAST);
					/*	mainMenu.getContentPane().add(
								new PfGeneral_menu(mainMenu, result
										.getMenues()), BorderLayout.CENTER);
						mainMenu.getContentPane().validate();*/
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}

				}
			});
		}
		return button_menu;
	}
	
	
	/**
	 * initialize management menu button
	 * this button switches to management menu handle operations
	 * 
	 * @return JButton button_management_menu
	 */
	private JButton get_button_management_menu() {
		if (button_management_menu == null) {
			Icon management_menuIcon = new ImageIcon("chef.png");
			Image img = ((ImageIcon) management_menuIcon).getImage();
			Image newimg = img.getScaledInstance(40, 40,
					java.awt.Image.SCALE_SMOOTH);
			management_menuIcon = new ImageIcon(newimg);
			button_management_menu = new JButton("ניהול תפריט", management_menuIcon);
			button_management_menu.setVerticalTextPosition(AbstractButton.BOTTOM);
			button_management_menu.setHorizontalTextPosition(AbstractButton.CENTER);
			button_management_menu
					.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			button_management_menu.setPreferredSize(new Dimension(120, 90));

			button_management_menu.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					
					//for kill thread
					((BorderLayout) mainMenu
							.getContentPane().getLayout())
							.getLayoutComponent(BorderLayout.CENTER).setVisible(false);
					//////////////////////
					
					MessageShowBusinessMenus msgShowMenu=new MessageShowBusinessMenus( );
					
					try {
						mainMenu.ms.client.sendToServer(msgShowMenu);
						MessageShowBusinessMenusReply resultMenu=(MessageShowBusinessMenusReply)mainMenu.ms.client.GetMessage();
						if(((BorderLayout) mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST)!=null)
						{
						mainMenu.getContentPane()
								.remove(((BorderLayout) mainMenu
										.getContentPane().getLayout())
										.getLayoutComponent(BorderLayout.EAST));
						}
						mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
						mainMenu.getContentPane().add(new PfSearch_business_menu(mainMenu,resultMenu.getResultMenu()), BorderLayout.CENTER);	
						mainMenu.getContentPane().add(new PanelFunctionsManagementMenu(mainMenu), BorderLayout.EAST);
						mainMenu.getContentPane().validate();
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				}
			});
		}
		return button_management_menu;
		
	}
	
	
}
